package com.example.kingdee.schedule;

import com.example.kingdee.common.StringUtils;
import com.example.kingdee.dto.SyncDto;
import com.example.kingdee.mapper.TBxStMapper;
import com.example.kingdee.service.JuShuiTanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * 聚水潭和云星空销售订单上传（云星空销售订单->聚水潭订单）
 */
@Component
@EnableScheduling
public class SalOrderSyncSchedule implements SchedulingConfigurer {

    //每1分钟执行一次
    private final String cron = "0 0/1 * * * ? ";

    @Autowired
    private JuShuiTanService juShuiTanService;
    @Autowired
    private TBxStMapper tBxStMapper;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(() -> {
//            List<Map<String, Object>> noSyncList = tBxStMapper.selectSalOrderSync();
//            for (Map<String, Object> noSync : noSyncList) {
//                String salBillNo = noSync.get("salBillNo") == null ? "" : noSync.get("salBillNo").toString();
//                Object id = noSync.get("id");
//                if (!StringUtils.isEmpty(salBillNo) && salBillNo.startsWith("HC")){
//                    SyncDto syncDto = new SyncDto();
//                    syncDto.setSyncType("销售订单上传");
//                    syncDto.setOrderId(noSync.get("keyValue"));
//                    //上传数据
//                    juShuiTanService.kindeeBillSync(syncDto);
//                }
//                //删除缓存数据
//                tBxStMapper.deleteSyncInfo(id);
//            }

        }, triggerContext -> {
            CronTrigger cronTrigger = new CronTrigger(cron);
            return cronTrigger.nextExecutionTime(triggerContext);
        });
    }
}
